#ifndef LOCAL_OPTIMIZATION_H_
#define LOCAL_OPTIMIZATION_H_

#include <iostream>

#include "Vector.h"

namespace local_minimizer
{

class Function
{
public:
	virtual double operator() (const Vector& position) const = 0;
};

class Director
{
public:
	virtual Vector operator() (const Function& function, const Vector& position, int iteration) const = 0;
};

class Searcher
{
public:
	virtual double operator() (const Function& function, const Vector& position, const Vector& direction) const = 0;
};

class Checker
{
public:
	virtual bool operator() (const Function& function, const Vector& position, int iteration) = 0;
};

Vector local_minimizer(const Function& function, const Vector& start, const Director& director, const Searcher& searcher, Checker& checker)
{
	Vector position=start;
	int iteration=0;
	while(!checker(function, position, iteration))
	{
		const Vector direction=director(function, position, iteration);
		const double step=searcher(function, position, direction);
		position=position+direction*step;
		iteration++;
	}
	return position;
}

}

#endif /* LOCAL_OPTIMIZATION_H_ */
